package com.lagou.dao;

import com.lagou.domain.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.SQLException;

public class UserDAO {

    // 创建QueryRunner对象
    private static QueryRunner qr = GenericDAO.getRunner();

    // 定义方法判断某个用户是否存在
    public static boolean find(User user) throws SQLException {
        String sql = "SELECT COUNT(*) FROM USER WHERE username = ? and password = ?";

        Object cnt = qr.query(sql, new ScalarHandler<>(), user.getUsername(), user.getPassword());
        long res = (long) cnt;

        return res > 0;
    }

}
